#pragma once

#include "config.h"

// Base interface for lyric providers (WORKING IN PROGRESS)
class NOVTABLE lyric_provider_base : public service_base
{
public:
	virtual void get_name(pfc::string_base & p_out) = 0;
	virtual bool get_description(pfc::string_base & p_out) { p_out = ""; return false; }
	virtual GUID get_context_guid() = 0;
	virtual GUID get_provider_guid() = 0;
	virtual void get_url(pfc::string_base & p_out) = 0;
	// Configruation Stuff
	virtual void get_global_config(lyrics_grabber_config_item * p_item) {}
	virtual bool have_config_popup() {return false;}
	virtual bool show_config_popup(HWND wnd_parent) {return false;}
	// Querying for lyrics
	virtual void query(metadb_handle_list_cref p_meta, pfc::string_list_impl & p_data, threaded_process_status & p_status, abort_callback & p_abort) = 0;

	//! Helpers
	static size_t g_write_memory_callback(void *ptr, size_t size, size_t nmemb, void *data);
	
	FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(lyric_provider_base)
};

typedef service_ptr_t<lyric_provider_base> lyric_provider_ptr;

class lyric_provider_lyricwiki : public lyric_provider_base
{
public:
	void get_name(pfc::string_base & p_out) { p_out = "LyricWiki"; }
	bool get_description(pfc::string_base & p_out)
	{ 
		p_out = "LyricWiki is a free site which is a source where anyone can go to get reliable lyrics for any song from any artist without being hammered by invasive ads.";
		return true; 
	}
	GUID get_context_guid()
	{ 
		// {FCEA8A87-EC11-403c-B9D4-A93AA08EA0F2}
		static const GUID context_guid = 
		{ 0xfcea8a87, 0xec11, 0x403c, { 0xb9, 0xd4, 0xa9, 0x3a, 0xa0, 0x8e, 0xa0, 0xf2 } };

		return context_guid;
	}
	GUID get_provider_guid()
	{
		return provider_guid;
	}
	void get_url(pfc::string_base & p_out)
	{
		p_out = "http://lyricwiki.org";
	}
	void get_global_config(lyrics_grabber_config_item * p_item)
	{
		m_config_item = p_item;
	}
	void query(metadb_handle_list_cref p_meta, pfc::string_list_impl & p_data, threaded_process_status & p_status, abort_callback & p_abort);

public:
	static const GUID provider_guid;

private:
	const lyrics_grabber_config_item * m_config_item;
};

class lyric_provider_lyricsplugin : public lyric_provider_base
{
public:
	void get_name(pfc::string_base & p_out) { p_out = "LyricsPlugin"; }
	bool get_description(pfc::string_base & p_out)
	{ 
		p_out = "LyricsPlugin.com is a great site providing a good many high quality lyrics for all genres.";
		return true; 
	}
	GUID get_context_guid()
	{ 
		// {4C674FB9-6BB9-4b21-B911-FBCC5478FF57}
		static const GUID context_guid = 
		{ 0x4c674fb9, 0x6bb9, 0x4b21, { 0xb9, 0x11, 0xfb, 0xcc, 0x54, 0x78, 0xff, 0x57 } };

		return context_guid;
	}
	GUID get_provider_guid()
	{
		return provider_guid;
	}
	void get_url(pfc::string_base & p_out)
	{
		p_out = "http://lyricsplugin.com";
	}
	void get_global_config(lyrics_grabber_config_item * p_item)
	{
		m_config_item = p_item;
	}
	void query(metadb_handle_list_cref p_meta, pfc::string_list_impl & p_data, threaded_process_status & p_status, abort_callback & p_abort);

public:
	static const GUID provider_guid;

private:
	const lyrics_grabber_config_item * m_config_item;
};

extern pfc::list_t<lyric_provider_ptr> g_lyric_provider_list;
